package com.softwareinlife.android.ux;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

public class WriteVision extends Activity implements OnTouchListener
{
	public Float x1;
	public Float y1;
	
	private TextView mDateDisplay;//���� ��¥ 
    private Button mPickDate;
    
    private TextView mDateDisplay2;//������ ��¥
    private Button mPickDate2;
    

    private int mYear;
    private int mMonth;
    private int mDay;
    
    private int mYear2;
    private int mMonth2;
    private int mDay2;
    

    static final int DATE_DIALOG_ID = 0;
    
    static final int DATE_DIALOG_ID2 = 0;
	
	
	
	@Override
    public void onCreate(Bundle savedInstanceState) 
    {
		
        super.onCreate(savedInstanceState);
        setContentView(R.layout.writevision);
        
        
        // capture our View elements
        mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
        mPickDate = (Button) findViewById(R.id.pickDate);
        
        mDateDisplay2 = (TextView) findViewById(R.id.dateDisplay2);
        mPickDate2 = (Button) findViewById(R.id.pickDate2);

        // add a click listener to the button
        mPickDate.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) 
            {
                showDialog(DATE_DIALOG_ID);
            }
        } );
        
        mPickDate2.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) 
            {
                showDialog(DATE_DIALOG_ID2);
            }
        } );
        
        
        
        
        // get the current date
        final Calendar c = Calendar.getInstance();
        final Calendar c2 = Calendar.getInstance();
        
        
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);

        mYear2 = c2.get(Calendar.YEAR);
        mMonth2 = c2.get(Calendar.MONTH);
        mDay2 = c2.get(Calendar.DAY_OF_MONTH);

        // display the current date
        updateDisplay();
        updateDisplay2();
        
    }
	

	@Override
    protected Dialog onCreateDialog(int id) 
    {
        switch (id) 
        {
        	case DATE_DIALOG_ID:
            
        	return new DatePickerDialog(this,
                   mDateSetListener,
                   mYear, mMonth, mDay);
        }
        
        switch (id)
        {
        	case DATE_DIALOG_ID2:
            
    		return new DatePickerDialog(this,
                    mDateSetListener2,
                    mYear2, mMonth2, mDay2);
        }
       
        
        	
        
        return null;
    }
	
	// the call back received when the user "sets" the date in the dialog
    private DatePickerDialog.OnDateSetListener mDateSetListener =
    	
            new DatePickerDialog.OnDateSetListener() 
    		{

                public void onDateSet(DatePicker view, int year, 
                                      int monthOfYear, int dayOfMonth) 
                {
                	mYear = year;
                    
                	mMonth = monthOfYear;
                    
                	mDay = dayOfMonth;
                    
                	updateDisplay();
                	
                }
            };
            
     // the call back received when the user "sets" the date in the dialog
            private DatePickerDialog.OnDateSetListener mDateSetListener2 =
            	
                    new DatePickerDialog.OnDateSetListener() 
            		{

                        public void onDateSet(DatePicker view2, int year2, 
                                              int monthOfYear2, int dayOfMonth2) 
                        {
                        	mYear2 = year2;
                            
                        	mMonth2 = monthOfYear2;
                            
                        	mDay2 = dayOfMonth2;
                            
                        	
                        	updateDisplay2();
                        }
                    };
	
	
	
	// updates the date we display in the TextView
    private void updateDisplay() 
    {
        mDateDisplay.setText
        (
            new StringBuilder()
                    // Month is 0 based so add 1
                .append(mMonth + 1).append("-")
                .append(mDay).append("-")
                .append(mYear).append(" ")
         );
        
       
        
        
    }
    
    private void updateDisplay2() 
    {
        mDateDisplay2.setText
        (
            new StringBuilder()
                    // Month is 0 based so add 1
                .append(mYear2).append("-")
                .append(mMonth2 +1 ).append("-")
                .append(mDay2).append(" ")
         );
    }
	
	@Override
	public boolean onTouchEvent(MotionEvent event) 
	{
	    	
		x1 = event.getX();//����� �� x�� ���Ͷ�~
		
		y1 = event.getY();//����� �� y�� ���Ͷ�~
		
			 try{
				 System.out.println("x ="+ x1.toString());
				 System.out.println("y ="+ y1.toString());
				 
			 }catch(Exception e){}
			 
			switch (event.getAction())
	        {
				case MotionEvent.ACTION_DOWN:
					
					
					if( x1 >= 90 && x1<= 227 && y1 >= 245 && y1 <= 290)
					{
						
						//Intent intent3 = net Intent(this,WriteVision.class);
						//startActivity(intent3);
					}
				break;
	        }
			return true;
	}
	
	
	
	@Override//��ġ �̺�Ʈ �ۼ��ϸ� �ڵ����� ���� ��? �ƴ� ����;;
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		return false;}
	
}